#include "nodes.hpp"
#include <thread>
#include <chrono>
#include <stdexcept>
#include <filesystem>

int main(int argc, char** argv) {
    BT::BehaviorTreeFactory factory;
    RegisterNodes(factory);

    // Use the absolute path to the XML file
    std::string xml_file = std::filesystem::absolute("myb.xml").string();

    // Check if the file exists
    if (!std::filesystem::exists(xml_file)) {
        throw std::runtime_error("The file " + xml_file + " does not exist.");
    }

    // Create the tree from the XML file
    auto tree = factory.createTreeFromFile(xml_file);

    // Execute the tree
    BT::NodeStatus status = BT::NodeStatus::RUNNING;
    while (status == BT::NodeStatus::RUNNING) {
        status = tree.tickRoot();
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }

    return 0;
}
